package com.survey.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.survey.common.core.domain.entity.SysUser;
import com.survey.system.service.ISysUserService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.survey.common.annotation.Log;
import com.survey.common.core.controller.BaseController;
import com.survey.common.core.domain.AjaxResult;
import com.survey.common.enums.BusinessType;
import com.survey.system.domain.SurIssueType;
import com.survey.system.service.ISurIssueTypeService;
import com.survey.common.utils.poi.ExcelUtil;
import com.survey.common.core.page.TableDataInfo;

/**
 * 问题类型Controller
 * 
 * @author ruoyi
 * @date 2024-12-25
 */
@RestController
@RequestMapping("/system/type")
public class SurIssueTypeController extends BaseController
{
    @Autowired
    private ISurIssueTypeService surIssueTypeService;
    @Autowired
    private ISysUserService sysUserService;

    /**
     * 查询问题类型列表
     */
    @PreAuthorize("@ss.hasPermi('system:type:list')")
    @GetMapping("/list")
    public TableDataInfo list(SurIssueType surIssueType)
    {
        startPage();
        List<SurIssueType> list = surIssueTypeService.selectSurIssueTypeListAdmin(surIssueType);
        return getDataTable(list);
    }

    /**
     * 导出问题类型列表
     */
    @PreAuthorize("@ss.hasPermi('system:type:export')")
    @Log(title = "问题类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SurIssueType surIssueType)
    {
        List<SurIssueType> list = surIssueTypeService.selectSurIssueTypeList(surIssueType);
        ExcelUtil<SurIssueType> util = new ExcelUtil<SurIssueType>(SurIssueType.class);
        util.exportExcel(response, list, "问题类型数据");
    }

    /**
     * 获取问题类型详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:type:query')")
    @GetMapping(value = "/{typeId}")
    public AjaxResult getInfo(@PathVariable("typeId") Long typeId)
    {
        return success(surIssueTypeService.selectSurIssueTypeByTypeId(typeId));
    }

    /**
     * 新增问题类型
     */
    @PreAuthorize("@ss.hasPermi('system:type:add')")
    @Log(title = "问题类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SurIssueType surIssueType)
    {
        surIssueType.setCreateBy(getUsername());
        return toAjax(surIssueTypeService.insertSurIssueType(surIssueType));
    }

    /**
     * 修改问题类型
     */
    @PreAuthorize("@ss.hasPermi('system:type:edit')")
    @Log(title = "问题类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SurIssueType surIssueType)
    {
        surIssueType.setUpdateBy(getUsername());
        return toAjax(surIssueTypeService.updateSurIssueType(surIssueType));
    }

    /**
     * 删除问题类型
     */
    @PreAuthorize("@ss.hasPermi('system:type:remove')")
    @Log(title = "问题类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{typeIds}")
    public AjaxResult remove(@PathVariable Long[] typeIds)
    {
        return toAjax(surIssueTypeService.deleteSurIssueTypeByTypeIds(typeIds));
    }

    /**
     * 修改问题类型状态
     */
    @PreAuthorize("@ss.hasPermi('system:type:edit')")
    @Log(title = "问题类型", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestBody SurIssueType surIssueType)
    {
        surIssueType.setUpdateBy(getUsername());
        return toAjax(surIssueTypeService.updateSurIssueType(surIssueType));
    }
}
